package com.community.mapper;

import com.community.pojo.ElderlyHealth;
import org.apache.ibatis.annotations.*;

public interface AdminElderlyHealthMapper {
    @Insert("INSERT INTO elderly_health (user_id , height, age, weight, health_condition) " +
            "VALUES (#{userId}, #{height}, #{age}, #{weight}, #{healthCondition})")
    @Options(useGeneratedKeys = true, keyProperty = "healthId")
    int addElderlyHealth(ElderlyHealth elderlyHealth);

    @Select("SELECT health_id AS healthId, " +
            "user_id AS userId, " +
            "height, " +
            "age, " +
            "weight, " +
            "health_condition AS healthCondition " +
            "FROM elderly_health " +
            "WHERE health_id = #{healthId}")
    ElderlyHealth findHealthById(Integer healthId);

    @Select("SELECT health_id AS healthId, " +
            "user_id AS userId, " +
            "height, " +
            "age, " +
            "weight, " +
            "health_condition AS healthCondition " +
            "FROM elderly_health " +
            "WHERE user_id = #{userId}")
    ElderlyHealth findElderlyHealthByuserId(Integer userId);

    @Delete("delete from elderly_health where health_id=#{healthId}")
    int deleteElderlyHealth(Integer healthId);

    @Delete("DELETE FROM elderly_health WHERE user_id = #{userId}")
    int deleteByUserId(Integer userId);

    @Update("update elderly_health set height=#{height},age=#{age},weight=#{weight},health_condition=#{healthCondition} where health_id=#{healthId}")
    int updateElderlyHealth(@Param("height") Double height,@Param("age") Integer age,
                            @Param("weight") Double weight, @Param("healthCondition") String healthCondition,
                            @Param("healthId") Integer healthId);
}
